<template>
  <div id="add_user_id">
    <el-dialog title="新增" :visible.sync="isShow.flig">
      <el-form ref="form" :model="user_form" label-width="80px" style="text-align: left;">
        <el-form-item label="账号角色" prop="rolename">
          <el-select v-model="user_form.roleid" placeholder="请选择账号角色">
            <el-option
              v-for="role in Role_list"
              :key="role.id"
              :value="role.id"
              :label="role.rolename"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="账号名称">
          <el-input v-model="user_form.username"></el-input>
        </el-form-item>

        <el-form-item label="账号密码">
          <el-input v-model="user_form.password"></el-input>
        </el-form-item>

        <el-form-item label="角色状态">
          <el-radio-group v-model="user_form.status">
            <el-radio :label="1">正常</el-radio>
            <el-radio :label="0">禁用</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="del_user_list">取 消</el-button>
        <el-button type="primary" @click="add_user_list">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { mapActions, mapState } from 'vuex';
export default {
  data() {
    return {
      user_form: {
        id: 0,
        username: "",
        roleid: "",
        password: "",
        status: 1
      }
    };
  },
  created(){
    this.RoleActions()
  },
  computed:{
    ...mapState({Role_list:state=>state.RoleStory.Role_list})
  },
  methods: {
    ...mapActions('RoleStory',['RoleActions']),
      setuser_list(obj){
         this.user_form={...obj}
      },
    add_user_list() {
      var url ='/useradd'
      if(this.user_form.id != 0){
          url='/useredit'
      }
      this.$http.post(url, this.user_form).then(res => {
        if (res.code == 200) {
          this.user_form = {
            id: 0,
            username: "",
            roleid: "",
            password: "",
            status: 1
          };
          this.isShow.flig=false
          this.$emit('reloadUser')
        }
      });
    },
    del_user_list(){
        this.user_form = {
            id: 0,
            username: "",
            roleid: "",
            password: "",
            status: 1
          };
          this.isShow.flig=false
    }
  },
  props: ["isShow", "User_list"]
};
</script>

<style>
</style>